
/**
 * @name Scene.Locker.TROutPutBlock
 * @class The <code>Locker</code> class constructs a locker block for friend
 * @augments GL2.Node
 * @param {Friend} friend.
 *
 */
exports.SocialScrollViewCell = Animation.AANode.subclass({
	/** @lends Scene.Locker.TROutPutBlock.prototype */	
    classname: 'SocialScrollViewCell',
    
    initialize: function($super, friend){
		$super();
		this._noOfFloors = 1
		this._friend = null;
		
		this._savePath = null;							
        this._outputImageSavePath = null;
        this._isPressed = false;
		
		this._friend = friend;
		this._outputImageSavePath = this.getBaseResourcePath()+'mugshot_output.png';
        
        this._activeImage = this.getBaseResourcePath()+'bgIconselected.png';
        this._pressedImage = this.getBaseResourcePath()+'bgIconhighlighted.png';
        this._inActiveImage = this.getBaseResourcePath()+'bgIcon.png';
        
		var visitButtonNormalPath = this.getBaseResourcePath() + "buy-normal.png";
		var visitButtonPressedPath = this.getBaseResourcePath() + "buy-pressed.png";
        
        this._blockAnchor = [0.5,0.5];
        this._blockSize = [TCUtil.adjustHeightWithDevice(100), TCUtil.adjustWidthWithDevice(100)];
        
        this._name = GLFactory.getText([TCUtil.getAdjustedX(0), TCUtil.getAdjustedY(10)], 100,this._friend.displayName, [TCUtil.getAdjustedX(70), TCUtil.getAdjustedY(30)], TCUtil.getAdjustedFontSize(90), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.5, 0.5], new Core.Color(0,0,0));
		this.addChild(this._name);
		
       	//this._floors = GLFactory.getText([TCUtil.getAdjustedX(0), TCUtil.getAdjustedY(25)], 100,""+this._noOfFloors, [TCUtil.getAdjustedX(70), TCUtil.getAdjustedY(30)], TCUtil.getAdjustedFontSize(90), null, null, GL2.Text.OverflowMode.ReduceFontSize, [0.5, 0.5], new Core.Color(0,0,0));
		//this.addChild(this._floors);
        
        this._blockBackgroundSprite = GLFactory.getSprite([TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0)], -2, this._inActiveImage, this._blockSize, this._blockAnchor);
        this.addChild(this._blockBackgroundSprite);
	
		this._mugShotImage = GLFactory.getSprite([TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0)], 2, this.getBaseResourcePath()+'mugshot_output.png', [TCUtil.adjustHeightWithDevice(130),TCUtil.adjustWidthWithDevice(120)], [0.5,1]);
		this._mugShotImage.setScale(.3,.3);
		this.addChild(this._mugShotImage);
		
		this._target = new GL2.TouchTarget();
        this._target.setAnchor(this._blockAnchor);
		this._target.setSize(this._blockSize);										  
		this.addChild(this._target);
		
		this._visitButton = new GLButton(visitButtonNormalPath, visitButtonPressedPath, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(30), this.onVisitTouch.bind(this), this, 3, "Visit",  new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
		this._visitButton.setPosition(TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(40));
	},
	
	onVisitTouch: function()
	{
		MMFriendActionManager.resetFriendCoinCollectedCount();
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(!TutorialManager.getHasCompletedTutorial())
		{
			if(this._friend.id == "999")
			{
				MMGameLayer.getControlLayer().getBottomBar().hideLeftTutorialIndicatorForMenu();
				GameCentralHandler.addUITransitionScreen();
				var neighborId = this._friend.id;
				DatabaseInterface._isVisitingNeighbor = true;	
				setTimeout(this.visitNeighborTimeOut.bind(this,neighborId),500);
			}
		}
		else
		{
			//console.log("zaki::::: "+this._noOfFloors);
			GameCentralHandler.addUITransitionScreen();
			var neighborId = this._friend.id;
			DatabaseInterface._isVisitingNeighbor = true;	
			setTimeout(this.visitNeighborTimeOut.bind(this,neighborId),500);
		}	
						   
	},
													   
	visitNeighborTimeOut: function(neighborId)
	{
		////console.log(">>>>>>>visitNeighbor");	
		GameCentralHandler.addTransitionScreen();											   
		GameCentralHandler.removeUITransitionScreen();
		
		//DatabaseHelper.setNeighborGamerTag(neighborId);
		
		if(this._friend.id == "999")
		{
			tempPath = "./Content/db/cobaltplay/"
			this.gameStateGetSuccess(tempPath);
		}
		else
		{								   
			GAGameStateGetHandler.getNeighbourGameState(this,neighborId);
		}
//		var testing = MMFriendActionManager.getFriendCoinActionState(neighborId);
//		console.log("zaki::::: FRIEND ACTION STATE IS"+testing);
		//MMFriendActionManager.saveFriendCoinActionState(["CobaltPlay",0,1]);
		//TODO remove scroll view here...
	},

	gameStateGetSuccess: function(path, files)
	{
		//DatabaseHelper.setNeighborName(this._friend.getGamertag());		
		//this._getParentTableView()._getParentTableView().destroyView();

		DatabaseHelper.loadUser();
		DatabaseInterface.loadNeighbor(path);
		MMFriendManager.setVisitingFriendObj(this._friend);
	},
	
	gameStateGetFailure: function(){
		var alertBox = UIFactory.getAlertBox(Core.Localization.getString("ERROR"), Core.Localization.getString("UNABLE_TO_LOAD_FRIEND"), ["ok"], this);
		DatabaseInterface._isVisitingNeighbor = false;	
		GameCentralHandler.destroyTransitionScreen();
    },

//	descriptionBlockInfo:function()
//	{
//        this._blockBackgroundSprite.setImage(this._activeImage, this._blockSize, this._blockAnchor);
//
//		this._isPressed = false;
//	},
		
	touchedBlock: function() 
	{
		//this.descriptionBlockInfo();
		//this._blockBackgroundSprite.setImage(this._activeImage, this._blockSize, this._blockAnchor);
		//this._isPressed = false;
	},
            
    inactivate: function()
    {
        this._isPressed = false;
        this._blockBackgroundSprite.setImage(this._inActiveImage, this._blockSize, this._blockAnchor);
    },

    blockPressed: function()
    {
        this._isPressed = true;                                          
        this._blockBackgroundSprite.setImage(this._pressedImage, this._blockSize, this._blockAnchor);
    },
	
	getSprite: function()
	{ 
		return this._blockBackgroundSprite; 
	},
	
	getTouchTarget: function() 
	{ 
		return this._target; 
	},
		
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/socialscrollview/";
	},
		
	destroy: function($super) 
	{
		for (var i = this._children.length - 1; i >= 0; i--) {
			this._children[i].destroy();
		}
		$super();
	},
});